using System;
using System.Collections.Generic;
using System.Text;

namespace Logging
{
    public class SimpleFormatter : Formatter
    {
        public override string Format(LogRecord record)
        {
            string format = "";
            format += record.Level.Name + " : " + record.Message + "\r\n";
            if (record.Millis != 0) format += "Time : " + new DateTime(record.Millis).ToString() + "\r\n";
            if (record.Exception != null)
            {
                Exception exc = record.Exception;
                while (exc != null)
                {
                    format += "Exception : " + record.Exception.GetType().FullName + " : " + record.Exception.Message + "\r\n";
                    format += record.Exception.StackTrace + "\r\n";
                    exc = exc.InnerException;
                    if (exc != null) format += "Caused By : ";
                }
            }
            if (record.SourceClassName != null) format += "Class : " + record.SourceClassName + "\r\n";
            if (record.SourceMethodName != null) format += "Method : " + record.SourceMethodName + "\r\n";
            if (record.Parameters != null && record.Parameters.Length > 0)
            {
                format += "Parameters :";
                foreach (object obj in record.Parameters)
                {
                    format += " " + obj.ToString();
                }
                format += "\r\n";
            }

            format += "\r\n";
            return format;
        }
    }
}
